package com.qf.controller;

import com.qf.service.CarService;
import com.qf.utils.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;

@RestController
@RequestMapping("/car")
public class CarController {

    @Autowired
    CarService carService;

    //主页面查询车次
    @GetMapping("/findByStarAndEnd")
    public ResultMsg findByStarAndEnd(String carStartaddr, String carEndaddr){
        return carService.findByStarAndEnd(carStartaddr,carEndaddr);
    }

    //主页面查询车次根据时间
    @GetMapping("/findByStarttime")
    public ResultMsg findByStarttime(String carStartaddr, String carEndaddr, String carStarttime){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date parse = null;
        try {
            parse = simpleDateFormat.parse(carStarttime);
            // 在这里的 "parse" 将只包含年月日信息
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        // 继续处理日期对象 parse
        return carService.findByStarttime(carStartaddr, carEndaddr, parse);
    }

    //根据车次id查询车辆信息
    @GetMapping("/findByCid")
    public ResultMsg findByCid(int carId){
        return carService.findByCid(carId);
    }

    //车站大屏信息查询
    @GetMapping("/findAll")
    public ResultMsg findAll(String cityName){
        return carService.findAll(cityName);
    }
    @GetMapping("/findAllByCityNameAndCarName")
    public ResultMsg findAllByCityNameAndCarName(String cityName,String carName){
        return carService.findAllByCityNameAndCarName(cityName,carName);
    }

    //车站大屏信息详情查询
    @GetMapping("/findByName")
    public ResultMsg findByName(String carName){
        return carService.findByName(carName);
    }
    //主页起始站信息挂载
    @GetMapping("/findAllStarName")
    public ResultMsg findAllStarName(){
        return carService.findAllStarName();
    }
    //主页终点站信息挂载
    @GetMapping("/findAllEndName")
    public ResultMsg findAllEndName(){
        return carService.findAllEndName();
    }
}
